package com.taobao.ic.scan.dao.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.taobao.common.dao.persistence.SqlMapBaseDAO;
import com.taobao.common.dao.persistence.exception.DAOException;
import com.taobao.ic.scan.dao.SpuImageDAO;
import com.taobao.ic.scan.route.DBRoutingFactory;
import com.taobao.item.domain.spu.SpuImageDO;

public class IbatisSpuImageDAO extends SqlMapBaseDAO implements SpuImageDAO {

	public long getMinImageId() throws DAOException {
		Map<String, Object> params = new HashMap<String, Object>();
		return (Long) this.executeQueryForObject(
				"OracleIbatisSpuImageDao.findMinSpuImageId", params,
				DBRoutingFactory.getOracleheart());
	}

	
	public long getMaxImageId() throws DAOException {
		// TODO Auto-generated method stub
		Map<String, Object> params = new HashMap<String, Object>();
		return (Long) this.executeQueryForObject(
				"OracleIbatisSpuImageDao.findCurMaxSpuImageId", params,
				DBRoutingFactory.getOracleheart());
	}

	
	public SpuImageDO getImageFromOracle(long imageId) throws DAOException {
		// TODO Auto-generated method stub
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("imageId", imageId);
		return (SpuImageDO) this.executeQueryForObject(
				"OracleIbatisSpuImageDAO.getImage", params,
				DBRoutingFactory.getOracleheart());
	}

	
	public SpuImageDO getImageFromMysql(long spuId, long imageId)
			throws DAOException {
		// TODO Auto-generated method stub
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("imageId", imageId);
		params.put("spuId", spuId);
		return (SpuImageDO) this.executeQueryForObject(
				"MysqlIbatisSpuImageDAO.getImageById", params,
				DBRoutingFactory.getMysqlspu());
	}

	@SuppressWarnings("unchecked")
	
	public List<SpuImageDO> getImageListByLimitRangeFromOracle(Date start,
			Date end) throws DAOException {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("startTime", start);
		params.put("endTime", end);
		return (List<SpuImageDO>) this.executeQueryForList(
				"OracleIbatisSpuImageDAO.getImagesByLimitDate", params,
				DBRoutingFactory.getOracleheart());
	}

	@SuppressWarnings("unchecked")
	
	public List<SpuImageDO> getImageListByLimitRowsFromOracle(long start,
			long end) throws DAOException {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("startNum", start);
		params.put("endNum", end);
		return (List<SpuImageDO>) this.executeQueryForList(
				"OracleIbatisSpuImageDAO.getImagesByLimitRows", params,
				DBRoutingFactory.getOracleheart());
	}

}
